<template>
  <div>
    <el-card>
      <p>就诊人管理</p>
      <el-form :model="form" label-width="120px">
        <el-form-item label="用户名">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="证件类型">
          <el-select
            v-model="form.certificatesType"
            style="width: 100%"
            placeholder="请选择"
          >
            <el-option label="身份证" value="10"></el-option>
            <el-option label="户口本" value="20"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码">
          <el-input v-model="form.contactsCertificatesNo" />
        </el-form-item>
        <el-form-item label="用户性别">
          <el-radio-group v-model="form.sex">
            <el-radio label="0" value="0">男</el-radio>
            <el-radio label="1" value="1">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="出生日期">
          <el-date-picker
            v-model="form.birthdate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input v-model="form.phone" />
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.address" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">确定</el-button>
          <el-button @click="qx">重写</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import instance from "../assets/axios";
const router = useRouter();
const form = ref({

});
const qx = () => {
  form.value = {};
};
const onSubmit = async () => {
  if (router.currentRoute.value.query.item == 0) {
    form.value.id = "";
    const res = await instance.post("/api/user/patient/auth/save", form.value);
    if (res.code == 200) {
      router.go(-1);
    }
  } else {
    form.value.id = router.currentRoute.value.query.id;
    const res = await instance.put("/api/user/patient/auth/update", form.value);
    if (res.code == 200) {
      router.go(-1);
    }
  }
};

onMounted(() => {
  if (router.currentRoute.value.query.item == 0) {
    form.value.id = "";
    // form.value.sex = "";
  } else {
    form.value.id = router.currentRoute.value.query.id;
    form.value = JSON.parse(router.currentRoute.value.query.item);
 console.log(form.value)
 form.value.sex=form.value.sex.toString();
 }
});
</script>